import React, { useEffect, useState } from 'react'
import Item from './Item'
import PubSub from 'pubsub-js'
export default function List() {
  //初始化一个state，保存订阅回来的数据，当订阅回来以后数据改变重新渲染
  const [searchList, setSearchList] = useState([])
  useEffect(() => {
    PubSub.subscribe('github', (_, data) => {
      setSearchList(data.data.items)
    })
  }, [])
  //给组件添加id，并将内容展开传递给子组件
  return (
    <div className="row">
      {
      searchList.map(item => {
        return <Item key={item.id}{...item} />
      })
      }
    </div>
  )
}
